package cst.a201sj.startproject201sj;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import cst.a201sj.startproject201sj.bean.WeatherInfo;
import cst.a201sj.startproject201sj.listener.WeatherListener;
import cst.a201sj.startproject201sj.modol.WeatherModol;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener {

    private EditText cityNOInput;
    private TextView city;
    private TextView cityNO;
    private TextView temp;
    private TextView wd;
    private TextView ws;
    private TextView sd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cityNOInput = (EditText) findViewById(R.id.et_city_no);
        city = (TextView) findViewById(R.id.tv_city);
        cityNO = (TextView) findViewById(R.id.tv_city_no);
        temp = (TextView) findViewById(R.id.tv_temp);
        wd = (TextView) findViewById(R.id.tv_WD);
        ws = (TextView) findViewById(R.id.tv_WS);
        sd = (TextView) findViewById(R.id.tv_SD);
        findViewById(R.id.button1).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button1:
                WeatherModol weathermodol=new WeatherModol();
                weathermodol.getWeather(cityNOInput.getText().toString(),this);
                break;
        }
    }

    @Override
    public void onResponse(WeatherInfo weather) {
if (weather!=null){
    city.setText(weather.getCity());
    cityNO.setText(weather.getCityid());
    temp.setText(weather.getTemp());
    wd.setText(weather.getWD());
    ws.setText(weather.getWS());
    sd.setText(weather.getSD());
}
else{
    city.setText("weizi");
}
    }

    @Override
    public void onFail(String msg) {
city.setText(msg);
    }
}
